import { request } from '@/apis';
import type { EditGroupParams, GroupNewsParams, AddGroupParams, GroupItemsParams, DeleteMemberParams, SearchParams, PushSettingParams } from './types';

const Api = {
  getGroupListAndCompanyId: '/user-center/monitors/getGroupListAndCompanyId',
  deleteGroup: (groupId: number) => `/user-center/monitors/${groupId}`,
  sortGroup: '/user-center/monitors/sort',
  editGroup: (groupId: number) => `/user-center/monitors/${groupId}`,
  getScreen: '/ep-query/screen/eventClassification',
  getGroupNews: (groupId: number) => `/ep-query/monitors/v2/${groupId}/news`,
  addGroup: '/user-center/monitors',
  getGroupItems: (groupId: number) => `/user-center/monitors/${groupId}/items`,
  deleteMember: (params: DeleteMemberParams) => `/user-center/monitors/detail/deleteByIds?groupId=${params.groupId}&ids=${encodeURIComponent(params.ids)}`,
  searchMember: '/ep-query/search',
  addMember: (groupId: number) => `/user-center/monitors/detail/addCompany?groupId=${groupId}`,
  excelImport: '/user-center/monitors/monitorCompanyExcelImport',
  txtImport: '/user-center/monitors/monitorCompanyInputImport',
  getPushSetting: '/user-center/push/v2/getDetailSettings',
  setPushSetting: (groupId: number) => `/user-center/push/v2/updateSettings/${groupId}`
};

export * from './types';

/** 获取组合列表 */
export const getGroupListAndCompanyId = () => request.get({ url: Api.getGroupListAndCompanyId, params: { limit: 9999, offset: 0 } });

/** 删除组合 */
export const deleteGroup = (groupId: number) => request.delete({ url: Api.deleteGroup(groupId) }, { isTransformResponse: false });

/** 组合排序 */
export const sortGroup = (params: string[]) => request.post({ url: Api.sortGroup, params }, { isTransformResponse: false });

/** 修改监控组合 */
export const editGroup = (groupId: number, params: EditGroupParams) => request.put({ url: Api.editGroup(groupId), params }, { isTransformResponse: false });

/** 获取筛选项 */
export const getScreen = () => request.get({ url: Api.getScreen });

/** 获取监控新闻 */
export const getGroupNews = (groupId: number, params: GroupNewsParams) => request.get({ url: Api.getGroupNews(groupId), params });

/** 新增组合 */
export const addGroup = (params: AddGroupParams) => request.post({ url: Api.addGroup, params }, { isTransformResponse: false });

/** 获取组合内企业列表 */
export const getGroupItems = (groupId: number, params: GroupItemsParams) => request.get({ url: Api.getGroupItems(groupId), params });

/** 删除组合成员 */
export const deleteMember = (params: DeleteMemberParams) => request.delete({ url: Api.deleteMember(params) }, { isTransformResponse: false });

/** 搜索成员 */
export const searchMember = (params: SearchParams) => request.get({ url: Api.searchMember, params });

/** 添加成员 */
export const addMember = (groupId: number, params: string[]) => request.post({ url: Api.addMember(groupId), params }, { isTransformResponse: false });

/** excel批量导入 */
export const excelImport = (params: FormData) => request.post({ url: Api.excelImport, headers: { 'Content-Type': 'multipart/form-data' }, params }, { isTransformResponse: false });

/** txt批量导入 */
export const txtImport = (params: string[]) => request.post({ url: Api.txtImport, params }, { isTransformResponse: false });

/** 获取推送设置 */
export const getPushSetting = () => request.get({ url: Api.getPushSetting });

/** 设置推送设置 */
export const setPushSetting = (groupId: number, params: PushSettingParams) => request.post({ url: Api.setPushSetting(groupId), params }, { isTransformResponse: false });
